package cc.ufinity.networkdiagnose.manager;
 
import java.io.InputStream;  
import org.xmlpull.v1.XmlPullParser;   
import android.util.Xml;

public class FTPConfigParser{
	 
    public FTPConfig parseFtpInfo(InputStream is) throws Exception {
        FTPConfig info = null;
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(is, "UTF-8");
        int type = parser.getEventType(); 
        while (type != XmlPullParser.END_DOCUMENT) {
            switch (type) {
            case XmlPullParser.START_DOCUMENT:  
                break;
            case XmlPullParser.START_TAG:
                String tag = parser.getName();
                if ("ftp".equals(tag)) {
                    info = new FTPConfig();
                } else if ("username".equals(tag)) {
                    type = parser.next();
                    info.userName =DESManager.getDesString(parser.getText());
                } else if ("pwd".equals(tag)) {
                    type = parser.next();
                    info.password = DESManager.getDesString(parser.getText());
                }else if ("ip".equals(tag)) {
                    type = parser.next();
                    info.address = DESManager.getDesString(parser.getText());
                }else if ("port".equals(tag)) {
                    type = parser.next();
                    String port = DESManager.getDesString(parser.getText());
                    port = port==null?"0":port;
                    info.port = Integer.parseInt(port);
                }
                break;
            case XmlPullParser.END_TAG:
                tag = parser.getName();
                if ("ftp".equals(tag)) {  
                }
                break;
            }
            type = parser.next();
        }
        is.close();
        return info;
    }
  
}
